Static Typing
Checking variable type
-
Returns the number corresponding to the variable type, associated with an ENUM described in
@GlobalScopeunder 'Variant.Type'.-
int typeof(x : Variant)
-
Changing variable type
-
Convert to 'string':
-
String str(x : Variant) -
String var_to_str(x : Variant)
-
Enums
-
"you can get that enum with:
EnumName.keys()[the_int]".
Casting
-
-
Dubious implementation and gives warnings when it shouldn't, ~kinda.
-
-
TLDR (I think):
-
Use:
-
var drag_data : DragData = data
-
-
Do not use:
-
var drag_data := data as DragData
-
-
Data Structures vs RefCounted vs Resource
-
"if I make
myobject.array = myarray, then when I change themyobject.array, themyarrayis not changed. When I do the same thing, but instead of making the object hold an array, I make it hold a Resource or RefCounted, it works, like somyobject.resource = myresource, so when I changemyobject.resourcethemyresourcechanges as well." -
"This also works with
myobject.node = mynode, but it was said that this could cause some memory leak problems."-
As stated in RefCounted documentation: no need to use free(), as these objects do it automatically when not in use. Same for Resource.
-
-
The choice between RefCounted and Resource depends on whether you want to use this data in the inspector.
-
RefCounted cannot be used in
@export; this causes an error.
-